class StaticType {
    constructor() {
        this.data = {

            // 期限类型
            dateType: [
                {
                    name: "year",
                    value: "1",
                    label: "年"
                },
                {
                    name: "quarter",
                    value: "2",
                    label: "季度"
                },
                {
                    name: "month",
                    value: "3",
                    label: "月"
                },
                {
                    name: "day",
                    value: "4",
                    label: "日"
                },
                {
                    name: "hour",
                    value: "5",
                    label: "小时"
                },
                {
                    name: "minute",
                    value: "6",
                    label: "分钟"
                },
                {
                    name: "time",
                    value: "7",
                    label: "次数"
                },
            ],
            // 状态类型
            statusType: [
                {
                    name: "enable",
                    value: "1",
                    label: "启用"
                },
                {
                    name: "disable",
                    value: "2",
                    label: "停用"
                },
                {
                    name: "deleted",
                    value: "3",
                    label: "删除"
                }
            ],
            // AppStatus组件type
            appStatusType: [
                {
                    name: "normal",
                    value: "1",
                    label: "normal"
                },
                {
                    name: "warning",
                    value: "2",
                    label: "warning"
                },
                {
                    name: "error",
                    value: "3",
                    label: "error"
                }
            ],
            // 服务方式 serveiceMode
            serviceModeType: [
                {
                    name: "count",
                    value: "1",
                    label: "数量"
                },
                {
                    name: "time",
                    value: "2",
                    label: "时长"
                },
                {
                    name: "counttime",
                    value: "3",
                    label: "数量+时长"
                }
            ],
            productType: [
                {
                    name: "product",
                    value: "0",
                    label: "标准产品"
                },
                {
                    name: "service",
                    value: "1",
                    label: "平台服务"
                },
                {
                    name: "package",
                    value: "2",
                    label: "业务包"
                },
                {
                    name: "third",
                    value: "3",
                    label: "第三方服务"
                },
                {
                    name: "plugin",
                    value: "4",
                    label: "插件"
                }
            ]
        }
    }

    // 更新枚举对象
    setStaticType(obj) {
        this.data = Object.assign({}, this.data, obj)
    }
    // 初始化新的下拉项, 适用name,value
    initNewData(str, arr = []) {
        let typeData = arr.map((item, index) => {
            return {
                name: str + index,
                value: item.value,
                label: item.name
            }
        })
        this.setStaticType({
            [str + 'Type']: typeData
        })
    }
    // 批量初始化新的下拉项
    initNewDataArr(arr) {
        arr.forEach(item => {
            this.initNewData(item.name, item.data)
        });
    }
    // 获取对应的静态枚举数组
    getStaticType = function (type) {
        if (!type) return
        return this.data[type]
    }
    // 获取获取对应的静态枚举对象
    getStaticTypeObj = function (type, value) {
        if (!(type && value)) return
        return this.data[type] && this.data[type].find(item => item.value == value) || {};
    }
    // 获取对应的静态枚举值label
    getStaticTypeLabel = function (type, value) {
        if (!(type && value)) return
        return this.getStaticTypeObj(type, value).label;
    }
    // 获取对应的静态枚举值value
    getStaticTypeValue = function (type, name) {
        if (!(type && name)) return
        let staticType = this.data[type] && this.data[type].find(item => item.name == name) || {};
        
        return staticType.value
    }
    // 获取对应的静态枚举值Name
    getStaticTypeName = function (type, value) {
        if (!(type && value)) return
        return this.getStaticTypeObj(type, value).name;
    }

}

export default StaticType